﻿using FCN;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2.Layer
{
   public class SigmodLayer
    {
        float[,] convoutdata;
        public float[,] forward(float[,] x)
        {
            convoutdata = Matrix.activation_Sigma(x).values;
            return convoutdata;
        }
        public float[,] backward(float[,] dout)
        {
            float[,] dx = Matrix.activation_Sigmabackward(convoutdata, dout).values;

            return dx;
        }

        public Matrix[,] convoutdataMatrix;
        public Matrix[,] forward(Matrix[,] x)
        {
            convoutdataMatrix= Matrix.activation_Sigma(x);
            
            return convoutdataMatrix;
        }
      public  Matrix[,] backward(Matrix[,] dout)
        {
            Matrix[,] dx = Matrix.activation_Sigmabackward(convoutdataMatrix, dout);

            return dx;
        }
        public float backward(int indexx,int indexy,int x,int y, float dout)
        {
            var outdata = convoutdataMatrix[indexx, indexy].values[x,y];
            float dx = dout * (1 - outdata) * outdata;
            //Matrix[,] dx = Matrix.activation_Sigmabackward(convoutdataMatrix, dout);

            return dx;
        }

        public Matrix[] convMatrix;
        public Matrix[] forward(Matrix[] x)
        {
            convMatrix = Matrix.activation_Sigma(x);

            return convMatrix;
        }
        public Matrix[] backward(Matrix[] dout)
        {
            Matrix[] dx = Matrix.activation_Sigmabackward(convMatrix, dout);

            return dx;
        }
        public float backward(int indexx, int x, int y, float dout)
        {
            var outdata = convMatrix[indexx].values[x, y];
            float dx = dout * (1 - outdata) * outdata;
            //Matrix[,] dx = Matrix.activation_Sigmabackward(convoutdataMatrix, dout);

            return dx;
        }
        float outdata;
        public float forward(float x) {
            outdata = (float)(1.0 / (1.0 + Math.Exp(-x))); 
            return outdata; 
          }
        public float backward(float dout)
        {
            float dx = dout * (1 - outdata) * outdata;

            return dx;
        }
    }
}
